﻿using System;
using System.Collections.Generic;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000EA7 RID: 3751
	internal class XInput : XSingleton<XInput>
	{
		// Token: 0x0600C7D6 RID: 51158 RVA: 0x002CB394 File Offset: 0x002C9594
		public override bool Init()
		{
			bool flag = this._async_loader == null;
			if (flag)
			{
				this._async_loader = new XTableAsyncLoader();
				this._async_loader.AddTask("Table/XOperation", this._reader, false);
				this._async_loader.Execute(null);
			}
			bool flag2 = !this._async_loader.IsDone;
			return !flag2;
		}

		// Token: 0x0600C7D7 RID: 51159 RVA: 0x002CB3FC File Offset: 0x002C95FC
		public override void Uninit()
		{
			this._async_loader = null;
		}

		// Token: 0x0600C7D8 RID: 51160 RVA: 0x002CB408 File Offset: 0x002C9608
		public void UnFreezed()
		{
			bool freezed = this.Freezed;
			if (freezed)
			{
				this._freeze_count = 1;
				this.Freezed = false;
			}
		}

		// Token: 0x170034CB RID: 13515
		// (get) Token: 0x0600C7D9 RID: 51161 RVA: 0x002CB434 File Offset: 0x002C9634
		// (set) Token: 0x0600C7DA RID: 51162 RVA: 0x002CB460 File Offset: 0x002C9660
		public bool Freezed
		{
			get
			{
				return XSingleton<XGesture>.singleton.Freezed && XSingleton<XVirtualTab>.singleton.Freezed;
			}
			set
			{
				bool flag = XSingleton<XScene>.singleton.bSpectator || value;
				bool flag2 = flag;
				if (flag2)
				{
					bool flag3 = this._freeze_count == 0;
					if (flag3)
					{
						XSingleton<XGesture>.singleton.Freezed = true;
						XSingleton<XVirtualTab>.singleton.Freezed = true;
						XSingleton<XActionSender>.singleton.Empty();
					}
					this._freeze_count++;
					bool flag4 = XSingleton<XGame>.singleton.CurrentStage is XConcreteStage;
					if (flag4)
					{
						XSingleton<XDebug>.singleton.AddLog("Freeze++: ", this._freeze_count.ToString(), null, null, null, null, XDebugColor.XDebug_None);
					}
				}
				else
				{
					this._freeze_count--;
					bool flag5 = this._freeze_count == 0;
					if (flag5)
					{
						XSingleton<XGesture>.singleton.Freezed = false;
						XSingleton<XVirtualTab>.singleton.Freezed = false;
					}
					else
					{
						bool flag6 = this._freeze_count < 0;
						if (flag6)
						{
							this._freeze_count = 0;
						}
					}
					bool flag7 = XSingleton<XGame>.singleton.CurrentStage is XConcreteStage;
					if (flag7)
					{
						XSingleton<XDebug>.singleton.AddLog("Freeze--: ", this._freeze_count.ToString(), null, null, null, null, XDebugColor.XDebug_None);
					}
				}
			}
		}

		// Token: 0x170034CC RID: 13516
		// (get) Token: 0x0600C7DB RID: 51163 RVA: 0x002CB58C File Offset: 0x002C978C
		public bool HasMove
		{
			get
			{
				return this._hasMove;
			}
		}

		// Token: 0x170034CD RID: 13517
		// (get) Token: 0x0600C7DC RID: 51164 RVA: 0x002CB5A4 File Offset: 0x002C97A4
		public bool HasEnemy
		{
			get
			{
				return this._hasEnemy;
			}
		}

		// Token: 0x170034CE RID: 13518
		// (get) Token: 0x0600C7DD RID: 51165 RVA: 0x002CB5BC File Offset: 0x002C97BC
		public bool HasNpc
		{
			get
			{
				return this._hasNpc;
			}
		}

		// Token: 0x170034CF RID: 13519
		// (get) Token: 0x0600C7DE RID: 51166 RVA: 0x002CB5D4 File Offset: 0x002C97D4
		public bool HasRole
		{
			get
			{
				return this._hasRole;
			}
		}

		// Token: 0x170034D0 RID: 13520
		// (get) Token: 0x0600C7DF RID: 51167 RVA: 0x002CB5EC File Offset: 0x002C97EC
		public bool HasDummy
		{
			get
			{
				return this._hasDummy;
			}
		}

		// Token: 0x170034D1 RID: 13521
		// (get) Token: 0x0600C7E0 RID: 51168 RVA: 0x002CB604 File Offset: 0x002C9804
		public float LastMoveAt
		{
			get
			{
				return this._last_move_at;
			}
		}

		// Token: 0x170034D2 RID: 13522
		// (get) Token: 0x0600C7E1 RID: 51169 RVA: 0x002CB61C File Offset: 0x002C981C
		public float LastEntityAt
		{
			get
			{
				return this._last_entity_at;
			}
		}

		// Token: 0x170034D3 RID: 13523
		// (get) Token: 0x0600C7E2 RID: 51170 RVA: 0x002CB634 File Offset: 0x002C9834
		public XEntity LastEnemy
		{
			get
			{
				return this._last_enemy;
			}
		}

		// Token: 0x170034D4 RID: 13524
		// (get) Token: 0x0600C7E3 RID: 51171 RVA: 0x002CB64C File Offset: 0x002C984C
		// (set) Token: 0x0600C7E4 RID: 51172 RVA: 0x002CB664 File Offset: 0x002C9864
		public XEntity LastNpc
		{
			get
			{
				return this._last_npc;
			}
			set
			{
				this._last_npc = value;
				this._hasNpc = (this._last_npc != null);
			}
		}

		// Token: 0x170034D5 RID: 13525
		// (get) Token: 0x0600C7E5 RID: 51173 RVA: 0x002CB680 File Offset: 0x002C9880
		public XEntity LastRole
		{
			get
			{
				return this._last_role;
			}
		}

		// Token: 0x170034D6 RID: 13526
		// (get) Token: 0x0600C7E6 RID: 51174 RVA: 0x002CB698 File Offset: 0x002C9898
		public XEntity LastDummy
		{
			get
			{
				return this._last_dummy;
			}
		}

		// Token: 0x170034D7 RID: 13527
		// (get) Token: 0x0600C7E7 RID: 51175 RVA: 0x002CB6B0 File Offset: 0x002C98B0
		public Vector3 LastMovePoint
		{
			get
			{
				return this._last_move_point;
			}
		}

		// Token: 0x170034D8 RID: 13528
		// (get) Token: 0x0600C7E8 RID: 51176 RVA: 0x002CB6C8 File Offset: 0x002C98C8
		public Vector3 LastGroundPoint
		{
			get
			{
				return this._last_ground_point;
			}
		}

		// Token: 0x170034D9 RID: 13529
		// (get) Token: 0x0600C7E9 RID: 51177 RVA: 0x002CB6E0 File Offset: 0x002C98E0
		public bool IsFxShield
		{
			get
			{
				return this._ally_fx_shield;
			}
		}

		// Token: 0x170034DA RID: 13530
		// (get) Token: 0x0600C7EA RID: 51178 RVA: 0x002CB6F8 File Offset: 0x002C98F8
		public bool IsMyFxShield
		{
			get
			{
				return this._my_fx_shield;
			}
		}

		// Token: 0x0600C7EB RID: 51179 RVA: 0x002CB710 File Offset: 0x002C9910
		public void OnEnterScene()
		{
			this._45hide = null;
			this._freeze_count = 0;
			XSingleton<XVirtualTab>.singleton.OnEnterScene();
			XSingleton<XGesture>.singleton.OnEnterScene();
			XSingleton<XGyroscope>.singleton.OnEnterScene();
			this.UpdateShieldOperation();
			this.UnFreezed();
		}

		// Token: 0x0600C7EC RID: 51180 RVA: 0x002CB750 File Offset: 0x002C9950
		public void OnLeaveScene()
		{
			this._last_npc = null;
		}

		// Token: 0x0600C7ED RID: 51181 RVA: 0x002CB75C File Offset: 0x002C995C
		public void UpdateShieldOperation()
		{
			XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
			bool flag = specificDocument != null;
			if (flag)
			{
				this._ally_fx_shield = (specificDocument.GetValue(XOptionsDefine.OD_Shield_Skill_Fx) != 0);
				this._mob_shield = (specificDocument.GetValue(XOptionsDefine.OD_Shield_Summon) != 0);
				this._my_fx_shield = (specificDocument.GetValue(XOptionsDefine.OD_Shield_My_Skill_Fx) != 0);
				bool flag2 = XSingleton<XEntityMgr>.singleton.Player != null;
				if (flag2)
				{
					List<XEntity> ally = XSingleton<XEntityMgr>.singleton.GetAlly(XSingleton<XEntityMgr>.singleton.Player);
					for (int i = 0; i < ally.Count; i++)
					{
						bool flag3 = ally[i].Skill != null && ally[i].Skill.SkillMobs != null;
						if (flag3)
						{
							for (int j = 0; j < ally[i].Skill.SkillMobs.Count; j++)
							{
								ally[i].Skill.SkillMobs[j].MobShield = this.MobShield(ally[i].Skill.SkillMobs[j]);
							}
						}
					}
				}
			}
		}

		// Token: 0x0600C7EE RID: 51182 RVA: 0x002CB8A8 File Offset: 0x002C9AA8
		public void UpdateDefaultCameraOperationByScene()
		{
			SceneTable.RowData sceneData = XSingleton<XSceneMgr>.singleton.GetSceneData(XSingleton<XScene>.singleton.SceneID);
			XOperationTable.RowData rowData = null;
			XOperationMode operationMode = XSingleton<XOperationData>.singleton.OperationMode;
			if (operationMode != XOperationMode.X25D)
			{
				if (operationMode - XOperationMode.X3D <= 1)
				{
					rowData = this._reader.GetByID((int)sceneData.OperationSettings[0]);
				}
			}
			else
			{
				rowData = this._reader.GetByID((int)sceneData.OperationSettings[1]);
			}
			bool flag = rowData != null;
			if (flag)
			{
				XSingleton<XOperationData>.singleton.CameraAngle = rowData.Angle;
				XSingleton<XOperationData>.singleton.CameraDistance = rowData.Distance;
				XSingleton<XOperationData>.singleton.AllowVertical = rowData.Vertical;
				XSingleton<XOperationData>.singleton.AllowHorizontal = rowData.Horizontal;
				XSingleton<XOperationData>.singleton.MaxVertical = rowData.MaxV;
				XSingleton<XOperationData>.singleton.MinVertical = rowData.MinV;
				XSingleton<XOperationData>.singleton.OffSolo = rowData.OffSolo;
			}
		}

		// Token: 0x0600C7EF RID: 51183 RVA: 0x002CB990 File Offset: 0x002C9B90
		public bool FxShield(XEntity e)
		{
			return (this._ally_fx_shield && e != null && !e.IsPlayer && XSingleton<XEntityMgr>.singleton.IsAlly(e)) || (this._my_fx_shield && e != null && e.IsPlayer);
		}

		// Token: 0x0600C7F0 RID: 51184 RVA: 0x002CB9DC File Offset: 0x002C9BDC
		public bool MobShield(XEntity e)
		{
			return this._mob_shield && e != null && e.MobbedBy != null && !e.MobbedBy.IsPlayer && e.MobShieldable && XSingleton<XEntityMgr>.singleton.IsAlly(e);
		}

		// Token: 0x0600C7F1 RID: 51185 RVA: 0x002CBA24 File Offset: 0x002C9C24
		public bool UpdateOperationMode()
		{
			bool isPlaying = XSingleton<XCutScene>.singleton.IsPlaying;
			bool result;
			if (isPlaying)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("Cannot change operation mode during cut-scene playing!", null, null, null, null, null);
				result = false;
			}
			else
			{
				bool flag = XSingleton<XGame>.singleton.CurrentStage is XConcreteStage;
				if (flag)
				{
					this.InnerOperationModeUpdate();
					result = true;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}

		// Token: 0x0600C7F2 RID: 51186 RVA: 0x002CBA84 File Offset: 0x002C9C84
		private void InnerOperationModeUpdate()
		{
			XSingleton<XGyroscope>.singleton.Cancel();
			XSingleton<XGesture>.singleton.Cancel();
			XOperationMode operationMode = XSingleton<XOperationData>.singleton.OperationMode;
			if (operationMode != XOperationMode.X25D)
			{
				if (operationMode - XOperationMode.X3D <= 1)
				{
					bool flag = this._45hide == null;
					if (flag)
					{
						this._45hide = GameObject.Find("Scene/45hide");
					}
					bool flag2 = this._45hide != null && !this._45hide.activeSelf;
					if (flag2)
					{
						this._45hide.SetActive(true);
					}
				}
			}
			else
			{
				bool flag3 = this._45hide == null;
				if (flag3)
				{
					this._45hide = GameObject.Find("Scene/45hide");
				}
				bool flag4 = this._45hide != null && this._45hide.activeSelf;
				if (flag4)
				{
					this._45hide.SetActive(false);
				}
			}
			XSingleton<XScene>.singleton.GameCamera.SetSightType();
		}

		// Token: 0x0600C7F3 RID: 51187 RVA: 0x002CBB7C File Offset: 0x002C9D7C
		private XEntity HitOnEnemy()
		{
			return null;
		}

		// Token: 0x0600C7F4 RID: 51188 RVA: 0x002CBB90 File Offset: 0x002C9D90
		private XEntity HitOnRole()
		{
			bool oneUpTouch = XSingleton<XGesture>.singleton.OneUpTouch;
			if (oneUpTouch)
			{
				bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall && XSingleton<XScene>.singleton.GameCamera.UnityCamera != null;
				if (flag)
				{
					Ray ray = XSingleton<XScene>.singleton.GameCamera.UnityCamera.ScreenPointToRay(XSingleton<XGesture>.singleton.TouchPosition);
					int num = 1 << LayerMask.NameToLayer("Role");
					bool flag2 = Physics.SphereCast(ray, 0.1f, out this._hit, float.PositiveInfinity, num);
					if (flag2)
					{
						string s = this._hit.collider.gameObject.name.StartsWith("mount_") ? this._hit.collider.gameObject.name.Substring(6) : this._hit.collider.gameObject.name;
						ulong id = 0UL;
						bool flag3 = ulong.TryParse(s, out id);
						if (flag3)
						{
							XEntity entity = XSingleton<XEntityMgr>.singleton.GetEntity(id);
							return (entity != null && entity.IsRole && !entity.IsPlayer) ? entity : null;
						}
						return null;
					}
				}
			}
			return null;
		}

		// Token: 0x0600C7F5 RID: 51189 RVA: 0x002CBCD8 File Offset: 0x002C9ED8
		private XEntity HitOnDummy()
		{
			bool oneUpTouch = XSingleton<XGesture>.singleton.OneUpTouch;
			if (oneUpTouch)
			{
				bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall && XSingleton<XScene>.singleton.GameCamera.UnityCamera != null;
				if (flag)
				{
					Ray ray = XSingleton<XScene>.singleton.GameCamera.UnityCamera.ScreenPointToRay(XSingleton<XGesture>.singleton.TouchPosition);
					int num = 1 << LayerMask.NameToLayer("Dummy");
					bool flag2 = Physics.SphereCast(ray, 0.1f, out this._hit, float.PositiveInfinity, num);
					if (flag2)
					{
						ulong id = 0UL;
						bool flag3 = ulong.TryParse(this._hit.collider.gameObject.name, out id);
						if (flag3)
						{
							XEntity entityConsiderDeath = XSingleton<XEntityMgr>.singleton.GetEntityConsiderDeath(id);
							return (entityConsiderDeath != null && entityConsiderDeath.IsDummy) ? entityConsiderDeath : null;
						}
						return null;
					}
				}
			}
			return null;
		}

		// Token: 0x0600C7F6 RID: 51190 RVA: 0x002CBDD0 File Offset: 0x002C9FD0
		private XEntity HitOnNpc()
		{
			bool oneUpTouch = XSingleton<XGesture>.singleton.OneUpTouch;
			if (oneUpTouch)
			{
				bool flag = XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.Hall && XSingleton<XScene>.singleton.GameCamera.UnityCamera != null;
				if (flag)
				{
					Ray ray = XSingleton<XScene>.singleton.GameCamera.UnityCamera.ScreenPointToRay(XSingleton<XGesture>.singleton.TouchPosition);
					int num = 1 << LayerMask.NameToLayer("Npc");
					bool flag2 = Physics.SphereCast(ray, 0.1f, out this._hit, float.PositiveInfinity, num);
					if (flag2)
					{
						ulong id = 0UL;
						bool flag3 = ulong.TryParse(this._hit.collider.gameObject.name, out id);
						if (flag3)
						{
							XEntity entity = XSingleton<XEntityMgr>.singleton.GetEntity(id);
							return (entity != null && entity.IsNpc) ? entity : null;
						}
						return null;
					}
				}
			}
			return null;
		}

		// Token: 0x0600C7F7 RID: 51191 RVA: 0x002CBEC8 File Offset: 0x002CA0C8
		private Vector3 HitOnGround()
		{
			return Vector3.zero;
		}

		// Token: 0x0600C7F8 RID: 51192 RVA: 0x002CBEE0 File Offset: 0x002CA0E0
		public void Update()
		{
			Vector3 vector = Vector3.zero;
			this._hasMove = false;
			this._hasEnemy = false;
			this._hasNpc = false;
			this._hasRole = false;
			this._hasDummy = false;
			XSingleton<XTouch>.singleton.Update();
			bool gestured = XSingleton<XGesture>.singleton.Gestured;
			if (gestured)
			{
				XEntity xentity = this.HitOnEnemy();
				this._hasEnemy = (xentity != null);
				XEntity xentity2 = this.HitOnNpc();
				this._hasNpc = (xentity2 != null);
				bool flag = !this._hasEnemy && !this._hasNpc;
				if (flag)
				{
					xentity2 = this.HitOnRole();
					this._hasRole = (xentity2 != null);
					this._last_role = (this._hasRole ? xentity2 : null);
					bool flag2 = !this._hasRole;
					if (flag2)
					{
						xentity2 = this.HitOnDummy();
						this._hasDummy = (xentity2 != null);
						this._last_dummy = (this._hasDummy ? xentity2 : null);
						bool flag3 = !this._hasDummy;
						if (flag3)
						{
							vector = this.HitOnGround();
							bool flag4 = vector != Vector3.zero;
							bool oneTouch = XSingleton<XGesture>.singleton.OneTouch;
							if (oneTouch)
							{
								this._hasMove = flag4;
								bool hasMove = this._hasMove;
								if (hasMove)
								{
									this._last_move_point = vector;
									this._last_move_at = Time.time;
								}
							}
							bool flag5 = flag4;
							if (flag5)
							{
								this._last_ground_point = vector;
							}
						}
					}
				}
				else
				{
					this._last_enemy = xentity;
					this._last_npc = xentity2;
					this._last_entity_at = Time.time;
				}
			}
		}

		// Token: 0x0400582D RID: 22573
		private GameObject _45hide = null;

		// Token: 0x0400582E RID: 22574
		private XEntity _last_enemy = null;

		// Token: 0x0400582F RID: 22575
		private XEntity _last_npc = null;

		// Token: 0x04005830 RID: 22576
		private XEntity _last_role = null;

		// Token: 0x04005831 RID: 22577
		private XEntity _last_dummy = null;

		// Token: 0x04005832 RID: 22578
		private Vector3 _last_move_point = Vector3.zero;

		// Token: 0x04005833 RID: 22579
		private Vector3 _last_ground_point = Vector3.zero;

		// Token: 0x04005834 RID: 22580
		private float _last_move_at = 0f;

		// Token: 0x04005835 RID: 22581
		private float _last_entity_at = 0f;

		// Token: 0x04005836 RID: 22582
		private RaycastHit _hit;

		// Token: 0x04005837 RID: 22583
		private int _freeze_count = 0;

		// Token: 0x04005838 RID: 22584
		private bool _hasMove = false;

		// Token: 0x04005839 RID: 22585
		private bool _hasEnemy = false;

		// Token: 0x0400583A RID: 22586
		private bool _hasNpc = false;

		// Token: 0x0400583B RID: 22587
		private bool _hasRole = false;

		// Token: 0x0400583C RID: 22588
		private bool _hasDummy = false;

		// Token: 0x0400583D RID: 22589
		private bool _ally_fx_shield = false;

		// Token: 0x0400583E RID: 22590
		private bool _mob_shield = false;

		// Token: 0x0400583F RID: 22591
		private bool _my_fx_shield = false;

		// Token: 0x04005840 RID: 22592
		private XTableAsyncLoader _async_loader = null;

		// Token: 0x04005841 RID: 22593
		private XOperationTable _reader = new XOperationTable();
	}
}
